//
//  ZZCH5WebVController.m
//  ZZC-Finance
//
//  Created by a on 2017/6/22.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCH5WebVController.h"
#import "ZZCLookPayPasswordController.h"

@interface ZZCH5WebVController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *H5WebV;
@property (strong, nonatomic) NSURLRequest *request;

@end

@implementation ZZCH5WebVController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    NSString *token = ZZCNSUserDefaults(@"token");
    _request = [NSURLRequest requestWithURL:[NSURL URLWithString:_h5Url]];
    //设置代理
    self.H5WebV.delegate = self;
    
    //让内容自动适应屏幕大小
    self.H5WebV.scalesPageToFit = YES;
    [self.H5WebV loadRequest:_request];
    [self.view addSubview:self.H5WebV];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
        NSLog(@"------> %@",request);
    NSString *strr;
    if ([request.URL.absoluteString containsString:ZZZZURL]) {
        NSLog(@"已拦截");
        NSString *str1 = [request.URL.absoluteString  substringFromIndex:ZZZZURL.length];
        NSLog(@"%@",str1);
        NSString *token = ZZCNSUserDefaults(@"token");
        strr = [NSString stringWithFormat:@"%@%@%@",ZZCURL_API,str1,token];
        NSLog(@"%@",strr);
        
        ZZCH5WebVController *h5vc = [ZZCH5WebVController new];
        h5vc.h5Url = strr;
        [self.H5WebV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strr]]];
        return NO;
    }
//
    if (([_H5WebV.request.URL.absoluteString containsString:_h5Url] && [request.URL.absoluteString containsString:@"back"]) || [request.URL.absoluteString containsString:@"finish"]){
   
        [self.navigationController popViewControllerAnimated:YES];
        NSLog(@"退出");
    } else if ([request.URL.absoluteString containsString:@"back"]){
        NSLog(@"@@@@@@@@@@@@%@",request);
        [self.H5WebV goBack];
        NSLog(@"返回上一层");
    } else if ([request.URL.absoluteString containsString:@"toPayPwd"]) {
        NSLog(@"忘记密码");
        ZZCLookPayPasswordController *forgerVC = [ZZCLookPayPasswordController new];
        [self.navigationController pushViewController:forgerVC animated:YES];
    }

  
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
